package com.qq5194102.simpleskills.model;

import com.qq5194102.simpleskills.core.PlayerDataManager;
import org.bukkit.entity.Player;

import java.util.Random;

/**
 * Created by 5194102 on 2025/7/13.
 * 玩家剑术技能数据模型
 */
public class SwordPlayerData extends BasePlayerSkillData{

    public SwordPlayerData() {
        super();
        this.skillName = "剑术";
        // 读取yml 计算经验、等级
        this.experience = 0;
    }

    public static final Random random = new Random();
    public static final int INITIAL_CRITICAL_STRIKE_RATE = 10; //初始10%暴击率
    public static final int INITIAL_CRITICAL_STRIKE_BONUS_RATE = 30; // 初始30%爆伤
    public static final int CRITICAL_STRIKE_RATE_RATIO = 1; // 1级加百分之1
    public static final int CRITICAL_STRIKE_BONUS_RATE_RATIO = 2; // 1级加百分之2爆伤

    //todo 静态代码块读取配置文件设置初始值  重载时重新读取
    /**
     * 计算暴击总伤害
     */
    public double getHandledDamage(double damage) {
        // 之后每一级增加1%概率
        int rate = getCriticalStrikeRate();
        int randomNum = random.nextInt(100);
        if (randomNum < rate){
            // 触发暴击 计算暴击伤害
            return damage * (1 + getCriticalStrikeBonusRate()/100.0);
        }else{
            return damage;
        }
    }
    /**
     * 获取暴击概率
     */
    public int getCriticalStrikeRate() {
        // 之后每一级增加1%概率
        int rate = INITIAL_CRITICAL_STRIKE_RATE + getLevel() * CRITICAL_STRIKE_RATE_RATIO;
        return Math.min(rate, 100);
    }
    /**
     * 获取暴击伤害加成率
     */
    public int getCriticalStrikeBonusRate() {
        // 之后每一级增加1%伤害
        int rate = INITIAL_CRITICAL_STRIKE_BONUS_RATE + getLevel() * CRITICAL_STRIKE_BONUS_RATE_RATIO;
        return Math.min(rate,300);
    }


    // 主动技能斩击伤害计算
    public double getActiveSkillDamage(){
        // 初始伤害5， 10级以上伤害7...
        if (this.getLevel()>=1000){
            return 200;
        }else if (this.getLevel()>=500){
            return 150;
        }else if (this.getLevel()>=300){
            return 100;
        }else if (this.getLevel()>=200){
            return 75;
        }else if (this.getLevel()>=100){
            return 40;
        }else if (this.getLevel()>=50){
            return 25;
        }else if (this.getLevel()>=30){
            return 15;
        }else if (this.getLevel()>=20){
            return 10;
        }else if (this.getLevel()>=10){
            return 7;
        }else{
            return 5;
        }
    }

    // 主动技能斩击距离计算
    public double getActiveDistance(){
        if (this.getLevel()>=1000){
            return 35;
        }else if (this.getLevel()>=500){
            return 30;
        }else if (this.getLevel()>=300){
            return 25;
        }else if (this.getLevel()>=200){
            return 20;
        }else if (this.getLevel()>=100){
            return 18;
        }else if (this.getLevel()>=50){
            return 15;
        }else if (this.getLevel()>=30){
            return 13;
        }else if (this.getLevel()>=20){
            return 10;
        }else if (this.getLevel()>=10){
            return 8;
        }else{
            return 5;
        }
    }
    // 主动技能斩击冷却时间 (毫秒)
    public long getActiveColdDown(){
        if (this.getLevel()>=150){
            return 5000;
        }else if (this.getLevel()>=100){
            return 6000;
        }else if (this.getLevel()>=50){
            return 7000;
        }else if (this.getLevel()>=20){
            return 8000;
        }else{
            return 1000;
        }
    }
}
